/*
declare type MethodDecorator = <T>(target: Object, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<T>) => TypedPropertyDescriptor<T> | void;
参数：
target: 对于静态成员来说是类的构造函数，对于实例成员是类的原型对象。
propertyKey: 成员的名字
descriptor: 成员的属性描述符。

*/

//方法注入代码
function logMethod(target: any, key: string, descriptor: PropertyDescriptor) {
    const originalMethod = descriptor.value;
  
    descriptor.value = function (...args: any[]) {
      console.log(`Calling method ${key} with arguments: ${JSON.stringify(args)}`);
      const result = originalMethod.apply(this, args);
      console.log(`Finished calling method ${key}. Result: ${result}`);
      return result;
    };
  
    return descriptor;
  }
  
  class Calculator {
    @logMethod
    add(a: number, b: number) {
      return a + b;
    }
  
    @logMethod
    multiply(a: number, b: number) {
      return a * b;
    }
  }
  
  const calculator = new Calculator();
  console.log(calculator.add(2, 3));
  console.log(calculator.multiply(4, 5));